package com.huage_06.lesson_04;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

public class HashMap03 {
    public static void main(String[] args) {
        //收集数据
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String str = sc.nextLine();

        //存储数据
        HashMap<Character,Integer> map = new HashMap<Character,Integer>();
        for (int i=0;i<str.length();i++){
            char ch = str.charAt(i);
            if(map.get(ch)==null){
                map.put(ch,1);
            }else {
                int num = map.get(ch)+1;
                map.put(ch,num);
            }
        }

        //输出统计数据
        StringBuilder sb = new StringBuilder();
        Set<Character> keySet = map.keySet();
        for (Character key : keySet){
            int number = map.get(key);
            sb.append(key).append("(").append(number).append(")");
        }
        String s = sb.toString();
        System.out.println("统计数据:" + s);
    }
}
